Page({
  data: {
    userInfo: {}, //用户信息
    openid: ''
  },
  async handleGetOpendId(e) {
      let that = this;
       wx.showModal({
      title: '操作提示',
      content: '确认登录吗',
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
           wx.cloud.callFunction({
      name: 'getOpenId',
      complete: res => {
        console.log("云函数获取到的openid", res.result.openid)
        let nowOpenid = res.result.openid;
        //将当前用户openid存入缓存
        //wx.setStorageSync('nowOpenid', res.result.openid)
        that.setData({
          openid: res.result.openid
        })

        console.log(that.data.openid);
        wx.request({
          url: 'http://127.0.0.1/owner/selectOpenid',
          data: {
            openid: this.data.openid
          },
          success: function (result) {
            console.log(result.data);
            //将用户的信息存储至本地
            wx.setStorageSync('userInfo', JSON.stringify(result.data))
            that.setData({
              userInfo: result.data
            })
            wx.reLaunch({
              url: '../my/my',
            })
          }
        })
      }


    })
        }
      }
    })
  
    //获取openid
   

  },
  changPhone(e) {
    wx.makePhoneCall({
      phoneNumber: '15507995485',
      success: function () {
        console.log("拨打电话成功");
      },
      fail: function () {
        console.log("拨打电话失败");
      }
    })
  },
  tuichu(e) {
    /* wx.showToast({
      icon:'loading',
      title: '确认退出吗',
    })
    wx.clearStorageSync()
    wx.reLaunch({
      url: '../my/my.wxml',
    }) */

    wx.showModal({
      title: '操作提示',
      content: '确认退出吗',
      complete: (res) => {
        if (res.cancel) {

        }

        if (res.confirm) {
          // wx.clearStorageSync();
          wx.removeStorageSync('userInfo');
          wx.reLaunch({
            url: '../my/my',
          });
        }
      }
    })
  },
  toRepair(e) {
    console.log(e.currentTarget.dataset.status);
    //将报修状态存储至本地
    wx.setStorageSync('repairStatus', e.currentTarget.dataset.status)
    wx.navigateTo({
      url: '/pages/repair/repair',
    })
  },

  touserBind() {
    wx.navigateTo({
      url: '/pages/userBind/userBind',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    console.log("onShow")
    // //读取用户的基本信息
    let userInfo = wx.getStorageSync("userInfo");
    console.log(userInfo)

    if (userInfo) {

      userInfo = JSON.parse(userInfo);
      this.setData({
        userInfo: userInfo
      })

    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  }
})